package STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.view;

import java.util.*;

import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.controllers.Controllers;
import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Book;
import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Reader;

public class View {
	
	private static Scanner scanner;

	public static void myPrint(String content){
		System.out.println(content);
	}
	
	public static void showMenu(){
		myPrint("----------- BOOK MANAGER ----------- ");
		myPrint("1. Add book");
		myPrint("2. List book");
		myPrint("3. Add Reader");
		myPrint("4. List Reader");
		myPrint("5. Borrow Book");
		myPrint("6. Show Borrow");
		myPrint("9. Exit");
		myPrint("Your choise [1-9]: ");
	}
	
	public static Book input(){
		int bookID, bookYear;
		String bookName, bookAuthor;
		String[] kindARR = {"Khoa học tự nhiên", "Văn học - Nghệ thuật", 
				"Điện tử viễn thông", "Công nghệ thông tin"};
		
		myPrint("ID: ");
		scanner = new Scanner(System.in);
		bookID = scanner.nextInt();
		myPrint("Name: ");
		scanner = new Scanner(System.in);
		bookName = scanner.nextLine();
		myPrint("Year: ");
		bookYear = scanner.nextInt();
		myPrint("Author: ");
		scanner = new Scanner(System.in);
		bookAuthor = scanner.nextLine();
		myPrint("Kind of Book: 0-Khoa học tự nhiên. 1-Văn học - Nghệ thuật. "
				+ "2-Điện tử viễn thông 3-Công nghệ thông tin");
		int i = scanner.nextInt();
		
		Book bookObj = new Book(bookID, bookYear, bookName, bookAuthor, kindARR[i]);
		
		return bookObj;
	}
	
	public static Reader input2(){
		int readerID, numberPhone;
		String readerName, readerAR;
		String[] jobARR = {"Sinh Viên", "Cao Học Viên", 
				"Giảng Viên"};
		
		myPrint("ID: ");
		scanner = new Scanner(System.in);
		readerID = scanner.nextInt();
		myPrint("Name: ");
		scanner = new Scanner(System.in);
		readerName = scanner.nextLine();
		myPrint("Phone Number: ");
		numberPhone = scanner.nextInt();
		myPrint("Address: ");
		scanner = new Scanner(System.in);
		readerAR = scanner.nextLine();
		myPrint("Kind of Book: 0-Sinh Viên. 1-Cao Học Viên. 2-Giảng Viên");
		int i = scanner.nextInt();
		
		Reader readerObj = new Reader(readerID, numberPhone, readerName, readerAR, jobARR[i]);
		
		return readerObj;
	}
	
	public static String findBook(){
		String bookName;
		
		myPrint("Book Name: ");
		scanner = new Scanner(System.in);
		bookName = scanner.nextLine();
		
		return bookName;
	}
	
	public static String findReader(){
		String readerName;
		
		myPrint("Reader Name: ");
		scanner = new Scanner(System.in);
		readerName = scanner.nextLine();
		
		return readerName;
	}

	public static void main(String[] args) {
		Controllers ctrObj = new Controllers();
		
		int functionID	= 0;
		boolean flag	= true;
		
		do {
			showMenu();
			
			try {
				scanner = new Scanner(System.in);
				functionID		= scanner.nextInt();
				
				switch (functionID) {
					case 1: ctrObj.checkInput(input());	                   break;
					case 2: ctrObj.checkOutput(); 	                       break;
					case 3: ctrObj.checkInput2(input2());	               break;
					case 4: ctrObj.checkOutput2();                         break;
					case 5: ctrObj.checkBorrow(findBook(), findReader());  break;
					case 6: ctrObj.checkShowBorrow();
					case 9:
					default:
						flag = false;
						break;
				}
				
			} catch (Exception e) {
				myPrint("Error! Please try again!");
				flag	= true;
			}
			
		} while (flag == true);
		
		
		
	}

}
